package cl.gob.minvu.catastromobile.util;

import java.util.List;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import cl.gob.minvu.catastromobile.R;
import cl.gob.minvu.catastromobile.entities.Comuna;

/**
 * @author psep
 *
 */
public class MyComunaAdapter extends ArrayAdapter<Comuna> {

	private Activity activity;

	/**
	 * This is the class constructor
	 * 
	 * @param context
	 * @param comunas
	 */
	public MyComunaAdapter(Context context, List<Comuna> comunas) {
		super(context, R.layout.list_comuna, comunas);
		this.activity = (Activity) context;
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		return this.getCustomView(position, convertView, parent);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return this.getCustomView(position, convertView, parent);
	}

	@SuppressLint("ViewHolder")
	public View getCustomView(int position, View convertView, ViewGroup parent) {
		Comuna comuna = getItem(position);

		LayoutInflater inflater = this.activity.getLayoutInflater();
		View row = inflater.inflate(R.layout.list_comuna, parent, false);
		TextView label = (TextView) row.findViewById(R.id.itemComuna);
		label.setText(comuna.nombre);

		return row;

	}

}
